#define _CRT_SECURE_NO_WARNINGS 1

#include<stdio.h>

typedef struct list
{
	int num;
	list* next;
}list;

int main()

{
	list* l = new list;
	l->next = NULL;
	list* p = l;
	list* temp = NULL;
	char c = 0;
	int num = -1;

	for (;;)
	{
		scanf("%d", &num);
		if ((c = getchar()) == ',')
		{
			if (-1!=num)
			{
				p->next = new list;
				p = p->next;
				p->num = num;
				temp = p;
			}
			break;
		}
		p->next = new list;
		p = p->next;
		p->num = num;
	}
	int i = 0;
	num = -1;
	for (;;)
	{
		scanf("%d", &num);
		if ((c = getchar()) == '}')
		{
			if (-1 != num&&0==i)
			{
				p->next = new list;
				p = p->next;
				p->num = num;
				temp = p;
				i++;
			}
			break;
		}
		p->next = new list;
		p = p->next;
		p->num = num;
		if (i == 0)
		{
			temp = p;
			i++;
		}
	}
	p->next = temp;

	if(temp&&0!=i)
	{
		list* front = l;
		list* rear = l;
		do
		{
			front = front->next;
			rear = rear->next->next;
		} while (front != rear);

		p = l;
		while (p != rear)
		{
			p = p->next;
			rear = rear->next;
		}
		printf("%d", p->num);
	}
	else
	{
		printf("NULL\n");
	}
	
	return 0;
}